﻿using System.Net.Sockets;
using System.Text;
using JPR.Common;

namespace JPR.TunelProxy.RequestGenerator.Helpers
{
	public static class RequestHelper
	{
		public static void SendRequest(HttpCommand command, string address, string objectName, int port)
		{
			StringBuilder sb = new StringBuilder();
			sb.Append(command.ToString().ToUpper());
			sb.Append(" ");
			sb.Append(objectName);
			sb.Append(" ");
			sb.Append("HTTP/1.1");
			sb.AppendLineBreak();
			sb.Append("Host: ");
			sb.Append(address);
			sb.AppendLineBreak();
			sb.Append("Proxy-Force: True");
			sb.AppendLineBreak();
			sb.Append("User-Agent: TunelProxy");
			sb.AppendLineBreak();
			sb.AppendLineBreak();
			byte[] buffer = Encoding.ASCII.GetBytes(sb.ToString());
			Socket socket =new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
			socket.Connect(address, port);
			socket.Send(buffer);
		}
	}
}